﻿@{
    ViewBag.Title = "Address";
    Layout = null;
}

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>地址管理</title>
    <link href="~/Content/Style/gobal.css" rel="stylesheet" type="text/css">
    <link href="~/Content/Style/address.css" rel="stylesheet" type="text/css">
    <!-- 引入 Vue -->
    <script src="https://unpkg.com/vue"></script>

    @*jqueryAlert提示框*@
    <link href="~/Content/alert/css/alert.css" rel="stylesheet" />
    <script src="~/Content/alert/js/alert.js"></script>
    <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>

</head>

<body>
    <div id="app" class="wrap">
        <div class="infor" v-for="item in UserSendAddr">
            <div class="infor_left">
                <div class="user">
                    <p class="icon"></p>
                    <p class="name"><span>{{item.Name}}</span>&nbsp;&nbsp;<span>{{item.TelNum}}</span></p>
                    <p class="del_icon"><a href="#" v-on:click="DeleteSendAddr(item)"></a></p>
                    <div class="clearfix"></div>
                </div>
                <p class="address">{{item.ContactDistrict + item.AddrContent}}</p>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="add_address">
            <a href="#" v-on:click="AddSendAddr()"><img src="../../Content/images/alter_icon-02.png" width="11" height="12">新增地址</a>
        </div>
        <div class="add_address">
            <a href="/Home/Index">去点餐</a>
        </div>
    </div>
</body>
</html>

<script type="text/javascript">
    var vm = new Vue({
        el: '#app',
        data() {
            return {
                UserSendAddr: [],
                shopnumber: '',
            };
        },
        created() {
            var _this = this;
            var GetRequest = new GetRequest();
            function GetRequest() {
                var url = location.search; //获取url中"?"符后的字串
                var theRequest = new Object();
                if (url.indexOf("?") != -1) {
                    var str = url.substr(1);
                    strs = str.split("&");
                    for (var i = 0; i < strs.length; i++) {
                        theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                    }
                }
                return theRequest;
            };
            _this.shopnumber = GetRequest.shopnumber;
            _this.IsAdd = GetRequest.IsAdd;

            $.ajax({
                url: "/Information/GetAllUserSendAddr",
                type: "POST",
                dataType: "json",
                data: { OpenId: "", AccID: _this.shopnumber, YZM: "", RETID: 1 },
                success: function (result) {
                    if (result.BS == 1) {
                        //console.log(result);
                        vm.UserSendAddr = result.rows;
                    }
                }
            });
        },
        methods: {
            AddSendAddr: function AddSendAddr() {
                var _this = this;
                window.location.href = "/Information/AddAddress?IsAdd=" + _this.IsAdd + "&shopnumber=" + _this.shopnumber;
            },
            DeleteSendAddr: function DeleteSendAddr(item) {
                //console.log(item);
                if (item.AccID != "" && item.OpenId != "") {
                    var dialog = jqueryAlert({
                        'title': '确认提示',
                        'content': "是否确认删除<font color='Red' size='3'>" + item.ContactDistrict + item.AddrContent + "</font>这个地址吗？",
                        'modal': true,
                        'buttons': {
                            '取消': function () {
                                dialog.close();
                            },
                            '确定': function () {
                                $.ajax({
                                    url: "/Information/UpdateUserSendAddr",
                                    type: "POST",
                                    dataType: "json",
                                    data: {
                                        "ID": item.ID,
                                        "AccID": item.AccID,
                                        "Name": item.Name,
                                        "TelNum": item.TelNum,
                                        "ContactDistrict": item.ContactDistrict,
                                        "AddrContent": item.AddrContent,
                                        "DistrictID": item.DistrictID,
                                        "OpenId": item.OpenId,
                                        "tag": 3
                                    },
                                    success: function (data) {
                                        if (data == 1) {
                                            setTimeout(function () { window.location.reload(); }, 500);
                                            jqueryAlert({
                                                'content': '删除成功'
                                            })
                                        }
                                        else {
                                            jqueryAlert({
                                                'content': '删除失败' + data
                                            })
                                        }
                                    }
                                });
                                dialog.close();
                            }
                        }
                    })
                }
                else {
                    jqueryAlert({
                        'content': '删除出错，请检查'
                    });
                }
            },
            
        }
    })
</script>


